package com.cancan.cloud.shop.controller;

import com.cancan.cloud.shop.domain.Product;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @program: cancan-java-share
 * @description: 产品控制器
 * @author: czchen
 * @date: 2023-02-01 14:33:46
 */
@RestController
public class ProductController {

    //用于验证负载均衡端口
    @Value("${server.port}")
    private String port;

    @RequestMapping("/api")
    public Product getApiById(Long id) {
        Product product = new Product();
        product.setId(100L);
        product.setPrice(new BigDecimal("999999.9999"));
        product.setName("黄金"+port);
        product.setStock(100);
        return product;
    }


    @GetMapping("/api2")
    public Product getApi2ById(Long id) {
        Product product = new Product();
        product.setId(id);
        product.setPrice(new BigDecimal("999999.9999"));
        product.setName("黄金"+port);
        product.setStock(100);
        //int i = 1/0;
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return product;
    }
}
